home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7771 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: athos.cc.bellcore.com!nyjets!papo
  2. From: papo@nyjets.NoSubdomain.NoDomain (Luis R Anaya)
  3. Newsgroups: comp.lang.pl1,comp.lang.c
  4. Subject: Re: PL/I and C
  5. Date: 28 Feb 1996 21:04:31 GMT
  6. Organization: Bell Communications Research
  7. Distribution: world
  8. Message-ID: <4h2g0v$qgg@athos.cc.bellcore.com>
  9. References: <4gh5ru$eng@goanna.cs.rmit.EDU.AU> <312CCEB2.4AB7@corp.dialog.com> <AD536AAB9668B76CD@mcdialb09.it.luc.edu> <312E363C.3CDE@corp.dialog.com> <mjs.825113139@hubcap> <AD568EA19668920AE@mcdiala11.it.luc.edu> <Pine.A32.3.91.960226003048.19148A-100000@black.weeg.uiowa.edu>
  10. NNTP-Posting-Host: nyjets.bigcat.bellcore.com
  11.  
  12. In article <Pine.A32.3.91.960226003048.19148A-100000@black.weeg.uiowa.edu>, The Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes:
  13. |> On Sun, 25 Feb 1996, Verne Arase wrote:
  14. |> 
  15. |> > In article <mjs.825113139@hubcap>,
  16. |> > mjs@hubcap.clemson.edu (M. J. Saltzman) wrote:
  17. |> 
  18. |> >  >|> In fact, if I recall correctly a pointer to x is implicitly an array.
  19. |> >  >
  20. |> > I was just explaining that in C, if you have a pointer, you also have an
  21. |> > array.
  22. |> 
  23. |>   If I declare char *ptr; in what sense have I gained an array?
  24.  
  25. I disagree.  when a pointer is declared you have a memory location.
  26. There is no array because no memory has been defined.  There is
  27. no difference between
  28.  
  29. int *foobar; DCL FOOBAR   PTR;
  30.  
  31. |> the difference between arrays and pointers, as does K&R2.
  32. |> 
  33. |> * when the array occurs without []s as an rvalue, as in
  34. |> int *p, a[10];
  35. |> p = a;
  36. |>   when it is operated on by the [] operator (a[6] becomes *(a + 6)),
  37. |>   and when it is passed as a parameter in a function call.
  38.  
  39. After memory has been declared...  Otherwise, you will end up with
  40. a reference to never-never land and at the end a core dump (or ABEND).
  41.  
  42. int *foobar;
  43. foobar = malloc (8*sizeof(int)); /* array of 0 to 7 */
  44.  
  45. foobar [1]=2;
  46.  
  47. ----
  48.  
  49. DCL ZMEMORY (8); /* from 1 to 8 */
  50. DCL FOOBAR PTR BASED (ADDR (ZMEMORY));
  51.  
  52. /* oh boy, am i rusty on PL/1 or what */
  53. /* I know that you can do this with REFER and controlled variables */
  54.  
  55. Regards,
  56.  
  57. -- 
  58. Luis Roberto Anaya-Rivera       papo@donuts0.bellcore.com     
  59. The Installator                 papo@bigcat.bellcore.com
  60. Bellcore, NJ                    n2zxe @ w2emu.nj.usa.na
  61.  
  62.